package com.smile.spring.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Copyright 上海申通快递总部
 * @company STO
 * @Date 2021/12/12 19:40
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("userService".equals(beanName)) {
            System.out.println("初始化前");
        }

        if ("personBean".equals(beanName)) {
            System.out.println("5.BeanPostProcessor.postProcessBeforeInitialization方法：到学校报名啦");
        }

        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("userService".equals(beanName)) {
            System.out.println("初始化后");
        }
        if ("personBean".equals(beanName)) {
            System.out.println("8.BeanPostProcessor#postProcessAfterInitialization方法：终于毕业，拿到毕业证啦！");
        }
        return bean;
    }
}
